package com.example.shaomengjie.smvp.view;

import android.animation.ObjectAnimator;
import android.animation.ValueAnimator;
import android.view.View;
import android.view.WindowManager;
import android.widget.ImageView;
import android.widget.RelativeLayout;

import com.bumptech.glide.Glide;
import com.example.shaomengjie.smvp.R;
import com.example.shaomengjie.smvp.bean.GuideBean;
import com.example.shaomengjie.smvp.framework.view.AppDelegate;

import java.util.List;

/**
 * Created by shaomengjie on 2017/6/23.
 */

public class  SplashADDelegate extends AppDelegate {

    private ImageView mSplashADIamge;
    private RelativeLayout mSplashADRoot;

    @Override
    public int getRootLayoutId() {
        return R.layout.activity_splash_ad;
    }

    @Override
    public void initWidget() {
        super.initWidget();
        mSplashADIamge = get(R.id.mSplashADImage);
        mSplashADRoot = get(R.id.mSplashADRoot);
    }
    public void loadADImageView(List<GuideBean> data){
        Glide.with(getActivity()).load(data.get(0).getImg_path()).centerCrop().into(mSplashADIamge);
        for (int i = 1; i < data.size(); i++) {
            ImageView imageView = createImageView();
            mSplashADRoot.addView(imageView);
            Glide.with(getActivity()).load(data.get(i).getImg_path()).into(imageView);
        }
    }

    private ImageView createImageView() {
        ImageView imageView = new ImageView(getActivity());
        imageView.setLayoutParams(new WindowManager.LayoutParams(WindowManager.LayoutParams.MATCH_PARENT, WindowManager.LayoutParams.MATCH_PARENT));
        imageView.setVisibility(View.GONE);
        imageView.setScaleType(ImageView.ScaleType.FIT_XY);
        return imageView;
    }
    public void showImageView(int position){
        View iamgeView = mSplashADRoot.getChildAt(position);
        iamgeView.setVisibility(View.VISIBLE);
        getAnim(iamgeView).start();
    }
    private ValueAnimator getAnim(View imageView){
        ValueAnimator animator = ObjectAnimator.ofFloat(imageView, "alpha",0,1);//淡出效果
        animator.setDuration(1000);
        return animator;
    }
}
